//
//  XYDJViewController.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/8/30.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "XYDJViewController.h"

#import "PGMXViewController.h"
@interface XYDJViewController ()
@property (weak, nonatomic) IBOutlet UILabel *labXYDJ;
@property (weak, nonatomic) IBOutlet UILabel *labJF;
@property (weak, nonatomic) IBOutlet UILabel *labDate;
@property (weak, nonatomic) IBOutlet UIImageView *moveImage;
@property (weak, nonatomic) IBOutlet UIView *lineView;

@property (weak, nonatomic) IBOutlet UIButton *fiveButton;
@property (weak, nonatomic) IBOutlet UIButton *fourButton;
@property (weak, nonatomic) IBOutlet UIButton *threeButton;
@property (weak, nonatomic) IBOutlet UIButton *twoButton;
@property (weak, nonatomic) IBOutlet UIButton *oneButton;


@property (nonatomic, strong) NSArray *buttonArray;

@end

@implementation XYDJViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self showNav:@"信用等级"];
    
    
    [self loadData];
    
    self.buttonArray = [[NSArray alloc]initWithObjects:self.oneButton,self.twoButton,self.threeButton,self.fourButton,self.fiveButton, nil];
}

- (IBAction)clickPG:(id)sender {
    PGMXViewController *pgmx = [[PGMXViewController alloc] init];
    [self.navigationController pushViewController:pgmx animated:YES];
}
//用户查看信用等级
- (void)loadData{
    [SVProgressHUD show];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    NSString *str = [NSString stringWithFormat:@"%@890d69e502d1d37a9e84335ccefece57",[user objectForKey:@"token2"]];
    NSString *token = [LCMD5Tool md5:str];
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:token forKey:@"verifyToken"];
    [parmas setObject:[user objectForKey:@"userid"] forKey:@"userid"];
    
    NSString *url = [NSString stringWithFormat:@"%@/App/Usercenter/userCredit",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"用户查看信用等级res:%@",responseObject);
        NSString *state = [NSString stringWithFormat:@"%li",[[responseObject objectForKey:@"status"] integerValue]];
        NSString *msg = [responseObject objectForKey:@"mssage"];
        if ([state integerValue] == 200) {
            _labJF.text = [NSString stringWithFormat:@"%li",[[responseObject objectForKey:@"content"] integerValue]];
            NSInteger p = [[responseObject objectForKey:@"content"] integerValue];
            [self setDashboard:p];
            [SVProgressHUD dismiss];
        }else{
            [SVProgressHUD showErrorWithStatus:msg];
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
        [SVProgressHUD dismiss];
    }];
    
    
}

- (void)setDashboard:(NSInteger )p{
    NSInteger t = 0;
    NSInteger b = 0;
    
    if (p > 700) {
        t = 5;
        b = 4;
        
    }
    
    if (p <= 700 || p > 650) {
        t = 4;
        b = 3;
    }
    
    if (p <= 650 || p > 600) {
        t = 3;
        b = 2;
    }
    
    if (p <= 600 || p > 550) {
        t = 2;
        b = 1;
    }
    
    if (p <= 550 || p > 350) {
        t = 1;
        b = 0;
    }
    
    if (p <= 350) {
        t = 0;
    }
    
    for (int i = 0; i < self.buttonArray.count; i ++) {
        UIButton *itemButton = [self.buttonArray objectAtIndex:i];
        if (i == b) {
            [itemButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [itemButton setBackgroundImage:[UIImage imageNamed:@"形状-4"] forState:UIControlStateNormal];
        }else{
            [itemButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
            [itemButton setBackgroundImage:nil forState:UIControlStateNormal];
        }
    }
    
    
    self.lineView.layer.anchorPoint = CGPointMake(1, 0.5);
    self.lineView.center = CGPointMake(187, 119);
    CGFloat angle = M_PI * 2 / 10 * t;
    self.lineView.transform = CGAffineTransformMakeRotation(angle);
    

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
